<?php
//$url="http%3A%2F%2Fsoso5.gtimg.cn%2Fsosopic_f%2F0%2F18140337536611869563%2F0";
$url=preg_replace("/\s*http\:\/\/.*http\:\/\//isx","http://",urldecode($url));
preg_match("/http\:\/\/(.*)\//Uisx",$url,$nn);$host=$nn[1];

$url=str_replace("BAIFENHAO","%",$url);
$haveReferer=1;
if(preg_match("/sinaimg\.cn/Uisx",$url)){
  $haveReferer=0;
}

if(preg_match("/39\.com/Uisx",$url)){
  $cookie="_wt_session_refer_cookie=http%253A%252F%252Fwww.39.net%252F; Hm_lpvt_ab2e5965345c61109c5e97c34de8026a=1350459594308; Hm_lpvt_1827105cf5cfac624c8dbf5159abfdb4=1350459576311; onlineId=4770284101207144433; area_info=CN450100|%D6%D0%B9%FA|%B9%E3%CE%F7|%C4%CF%C4%FE%CA%D0|%B5%E7%D0%C5; Hm_lvt_ab2e5965345c61109c5e97c34de8026a=1350459575708; Hm_lvt_1827105cf5cfac624c8dbf5159abfdb4=1350459576311";
}

if(preg_match("/photo\.sina\.com\.cn/Uisx",$url)){
  $cookie="U_TRS1=0000002a.5ede4b18.51a9ace5.29e7cc12; U_TRS2=0000002a.5eeb4b18.51a9ace5.a6fa6e22; UOR=,club.edu.sina.com.cn,; Apache=5411857267557.991.1370074365751; SINAGLOBAL=5411857267557.991.1370074365751; ULV=1370074365762:1:1:1:5411857267557.991.1370074365751:";
}

if(preg_match("/qq\.com/Uisx",$url)){
  $cookie="pgv_pvid=6712437708; pgv_info=ssid=s873852037; qqmusic_uin=12345678; qqmusic_key=12345678; qqmusic_fromtag=6; pt2gguin=o1173550923; uin=o1173550923; skey=@jtHUrXOcH; ptisp=ctc; RK=S0aa0gQfTx; o_cookie=1173550923";
}

$cookie=($cookie!="")?"\r\nCookie: ".trim($cookie)."":"";
preg_match_all("/http\:\/\/([^\/]*)(\/[^<>\"\s]*)$/Uisx",$_GET[url],$nn);
$post=<<<TEXT
GET {$url} HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, */ *
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; Foxy/1; QQDownload 702; GTB7.2; Foxy/1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)
Referer: http://{$host}
Accept-Encoding: gzip, deflate
Host: {$host}{$cookie}
Connection: Keep-Alive


TEXT;
//$cookie="360docArtPageBackGroundColor=mainbj6; Hm_lvt_d86954201130d615136257dde062a503=1388564015,1388667001,1388667311; Hm_lpvt_d86954201130d615136257dde062a503=1388667311";
//$Referer="http://image25.360doc.com";
$nr=curl38($url,$cookie,$Referer);

if(trim($nr)==""){
    echo $url;
} else{
    echo $nr;
}


function curl38($url, $cookie="",$Referer="")
{
    global $host;
    $timeout = 15;
    $url=trim(chop($url));
    //$url = str_replace("%", "%25", $url);
    $Referer="http://".$host."/";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, trim(chop($url)));
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0");
    if($Referer) curl_setopt($ch, CURLOPT_REFERER, $Referer);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
        'X-Requested-With: XMLHttpRequest',
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
        'Accept-Encoding: gzip, deflate',
        'Connection: Keep-Alive',
    ));
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    ob_start();
    curl_exec($ch);
    curl_close($ch);
    $result = ob_get_contents();
    ob_end_clean();

    preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
    $result = $nn[2];
    if (@gzinflate(substr($result, 10))) {
        $result = gzinflate(substr($result, 10));
    }
    return $result;
}


?>